#!/bin/bash

err_exit() {
    echo $1
    exit $2
}

# ktouch安装流程
ktouch_install() {
    tar -xf $userdir/kyo_env/ktouch.tar -C /tmp/
    cd /tmp/ktouch/
    ./install.sh
}

# vim配置流程
vim_config() {
    mv $userdir/kyo_env/kyo_vim $userdir/
    su felix -c "$userdir/kyo_vim/linux_install.sh"
}

test $UID -eq 0 || err_exit "请使用sudo运行!"

user=felix
userdir=/home/$user

# ktouch
which ko &> /dev/null || ktouch_install

# 配置vim
ls $userdir/kyo_vim &> /dev/null || vim_config

# tmux
apt install tmux xclip -y
cp $userdir/kyo_env/tmux.conf $userdir/.tmux.conf
chown $user:$user $userdir/.tmux.conf

# sogoupinyin
dpkg -i $userdir/kyo_env/sogoupinyin_2.1.0.0086_amd64.deb
apt-get -f install -y

dpkg -i $userdir/kyo_env/VNC-Viewer-6.17.1113-Linux-x64.deb
apt-get -f install -y

# 键盘快捷键
# gsettings set org.gnome.desktop.keybindings.wm increase-opacity "['<Primary><Alt>equal']"
# gsettings set org.gnome.desktop.keybindings.wm decrease-opacity "['<Primary><Alt>minus']"
# gsettings set org.gnome.libgnomekbd.keyboard options "['ctrl\tctrl:swapcaps', terminate\tterminate:ctrl_alt_bksp]"

test -d $userdir/.local/bin || mkdir $userdir/.local/bin -p
cp genSpeaker ksql $userdir/.local/bin/
chown $user:$user $userdir/.local/bin -R
chmod +x $userdir/.local/bin/genSpeaker $userdir/.local/bin/ksql

mv $userdir/kyo_env/chromium-vim $userdir/
chown $user:$user $userdir/chromium-vim -R

# 执行鼠标禁用程序
#chmod +x $userdir/kyo_env/dm_ins
#$userdir/kyo_env/dm_ins 3.3.3.3

